﻿var routineinspectionRecordListTableVue = new Vue({
    el: "#routineinspectionRecordListTable",
    data: {
        pageModel: {
            pageIdx: 1,
            pageSize: 10,
            pageTotal: 0,
            pageLength: 0,
            reults: []
        },
        searchModel: {
            queryFormID: 0,
            isAsc: true,
            isAll: true
        },
        templateFormList: [],
        typeDictionary: {},
        isDisableDictionary: {},
        approvalStatusDictionary: {},   //签核状态字典
    },
    methods: {
        AddRecord: function () {
            AddRoutineInspectionRecord(this);
        },
        EditRecord: function (recordID) {
            EditRoutineInspectionRecord(this, recordID);
        },
        DeleteRecord: function (record) {
            DeleteRoutineInspectionRecord(this, record);
        },
        GotoPage: function (toPageIdx) {
            this.pageModel.pageIdx = toPageIdx;
            ListRoutineInspectionRecordForPage(this);
        },
        SearchRecord: function () {
            this.pageModel.pageIdx = 1;
            this.searchModel.isAll = false;
            ListRoutineInspectionRecordForPage(this);
        },
        SearchReset: function () {
            this.pageModel.pageIdx = 1;
            this.searchModel.queryFormID = 0;
            this.searchModel.isAll = true;
            ListRoutineInspectionRecordForPage(this);
        }
    },
    filters: {
        FormatCSharpDate: function (value) {
            return CSharpToJsDate(value);
        }
    },
    created: function () {
        //页面加载前初始的数据
        InitialAztechScript();
    },
    mounted: function () {
        //页面加载后初始的数据
        this.typeDictionary = GlobalDictionary.GetEquipmentTypeDictionary();
        this.isDisableDictionary = GlobalDictionary.GetTrueOrFalseDictionary();
        this.approvalStatusDictionary = GlobalDictionary.GetApprovalStatusDictionary();

        ListTemplateForm(this);
        ListRoutineInspectionRecordForPage(this);
    }
});

/**
 * 查询所有点检记录
 */
function ListRoutineInspectionRecordForPage(vue) {
    ShowAzLoading();
    $.ajax({
        type: "POST",
        url: "/RoutineInspection/ListRoutineInspectionRecordForPage?v=" + Math.random(),
        data: { pageModel: vue.pageModel, searchModel: vue.searchModel },
        success: function (res) {
            if (res.status == "Success") {
                vue.pageModel = res.data;
            } else {
                toastr.error(res.message);
            }
            HideAzLoading();
        },
        error: function (err) {
            console.log(err);
            HideAzLoading();
            toastr.error("服务器发生错误，请稍候再试An error occurred in the server. Please try again later。");
        }
    })
}

/**
 * 新增点检单模板信息
 */
function AddRoutineInspectionRecord(vue) {
    OpenAzModal("新增点检记录Add routine check record", "/RoutineInspection/Page/RecordDetail?IsNew=true", function () {
        ListRoutineInspectionRecordForPage(vue);
    });
}

/**
 * 编辑点检单模板信息
 */
function EditRoutineInspectionRecord(vue, recordID) {
    OpenAzModal("编辑点检记录Edit routine check record", "/RoutineInspection/Page/RecordDetail?RecordID=" + recordID, function () {
        ListRoutineInspectionRecordForPage(vue);
    });
}

/**
 * 查询所有可用点检单模板
 */
function ListTemplateForm(vue) {
    ShowAzLoading();
    $.ajax({
        type: "GET",
        url: "/RoutineInspection/ListTemplateForm?IsDisable=false&v=" + Math.random(),
        success: function (res) {
            //console.log(res);
            if (res.status == "Success") {
                //设置可选点检单模板
                vue.templateFormList = res.data;
            } else {
                toastr.error(res.message);
            }
            parent.HideAzLoading();
        },
        error: function (err) {
            parent.HideAzLoading();
            console.log(err);
        }
    });
}

/**
 * 删除点检记录信息
 */
function DeleteRoutineInspectionRecord(vue, record) {
    var message = "确认删除confirm deletion【" + record.Equipment.BaseInfo.Code + "】点检记录check record【" + record.BaseInfo.ID + "】?";
    if (confirm(message)) {
        ShowAzLoading();
        $.ajax({
            type: "POST",
            url: "/RoutineInspection/DeleteRoutineInspectionRecord",
            data: { RecordID: record.BaseInfo.ID },
            success: function (res) {
                if (res.status == "Success") {
                    toastr.success("删除点检记录信息成功Routine check record information deleted successfully。");
                    ListRoutineInspectionRecordForPage(vue);
                } else {
                    toastr.error(res.message);
                }
                HideAzLoading();
            },
            error: function (err) {
                console.log(err);
                toastr.error("服务器发生错误，请稍候再试An error occurred in the server. Please try again later。");
                HideAzLoading();
            }
        })
    }
}